<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="crm.util.ParamUtil"%>
<%@page import="java.util.Collection"%>
<%@page import="crm.control.BargainControl"%>
<%@page import="java.util.Iterator"%>
<%@page import="crm.model.Bargain"%>
<%@page import="crm.model.Offer"%>
<%@page import="crm.control.OfferControl"%>
<%@page import="java.util.HashMap"%>
<%@page import="crm.util.DateTime"%>
<%@page import="crm.model.Employees"%>
<%@page import="crm.control.EmployeesControl" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>天成科技CRM管理系统</title>
<!--                       CSS                       -->
<!-- Reset Stylesheet -->
<link rel="stylesheet" href="../../../resources/css/reset.css" type="text/css" media="screen" />
<!-- Main Stylesheet -->
<link rel="stylesheet" href="../../../resources/css/style.css" type="text/css" media="screen" />
<!-- Invalid Stylesheet. This makes stuff look pretty. Remove it if you want the CSS completely valid -->
<link rel="stylesheet" href="../../../resources/css/invalid.css" type="text/css" media="screen" />
<!--                       Javascripts                       -->
<!-- jQuery -->
<script type="text/javascript" src="../../../resources/scripts/jquery-1.3.2.min.js"></script>
<!-- jQuery Configuration -->
<script type="text/javascript" src="../../../resources/scripts/simpla.jquery.configuration.js"></script>
 <script type="text/javascript" src="../../../resources/js/WebCalendar.js"></script>
<!-- Facebox jQuery Plugin -->
<script type="text/javascript" src="../../../resources/scripts/facebox.js"></script>
<!-- jQuery WYSIWYG Plugin -->
<script type="text/javascript" src="../../../resources/scripts/jquery.wysiwyg.js"></script>
<!-- jQuery Datepicker Plugin -->
<script type="text/javascript" src="../../../resources/scripts/jquery.datePicker.js"></script>
<script type="text/javascript" src="../../../resources/scripts/jquery.date.js"></script>
<script type="text/javascript" src="../../../resources/js/reinitIframe.js"></script>
<script type='text/javascript'>
window.onload=function(){
	var num=document.getElementById('num').value;
	setInterval(function(){
		//new ReinitIframe('iadd');
		new ReinitIframe('iinformation');
		for(var i=1;i<=num;i++){
			var check = 'icheck' + i;
			new ReinitIframe(check);
		}
	},200);
}


</script>
<style type="text/css">
.hide{
    position: absolute;
    zoom: 0.001;
    -moz-transform: scale(0);
    -webkit-transform: scale(0);
    -o-transform: scale(0);
    transform: scale(0);
}
</style>
</head>
	<body>
		<%
		    request.setCharacterEncoding("UTF-8");
		    String bargain_id = "";
		    String title = "";
			String is_overdue = "";
			String currentPerson = "";
			Employees cu = (Employees)session.getAttribute("user");

			int type = ParamUtil.getInt(request, "type", 1);
			if (type == 1) {
			    bargain_id = ParamUtil.getString(request,"bargain_id",null);
				is_overdue = ParamUtil.getString(request, "is_overdue", null);
				currentPerson = ParamUtil.getString(request, "currentPerson", null);
				title = ParamUtil.getString(request, "offer_theme", null);
				

				session.setAttribute("bargain_id",bargain_id);
				session.setAttribute("is_overdue", is_overdue);
				session.setAttribute("currentPerson", currentPerson);
				session.setAttribute("title", title);
			} else {
			    bargain_id = (String) session.getAttribute("bargain_id");
				is_overdue = (String) session.getAttribute("is_overdue");
				currentPerson = (String) session.getAttribute("currentPerson");
				title = (String) session.getAttribute("title");
			}
		%>
	<div id="body-wrapper">
  <!-- Wrapper for the radial gradient background -->
  <div id="sidebar">
    <div id="sidebar-wrapper">
      <!-- Sidebar with logo and menu -->
      <h1 id="sidebar-title"><a href="#">Simpla Admin</a></h1>
      <!-- Logo (221px wide) -->
      <a href="#"><img id="logo" src="../../../resources/css/slice/notice.png" alt="Simpla Admin logo" /></a>
      <!-- Sidebar Profile links -->
      <div id="profile-links"><a href="#" title="Edit your profile"><%=EmployeesControl.getEmployeesName(cu.getId())%>,您好！</a><a href="#messages" rel="modal" title="3 Messages"></a><br />
        <br />
        <a href="#information" rel='modal' >修改个人信息</a> | <a href="../../login/logout.jsp" title="Sign Out">注销</a> </div>
      <ul id="main-nav">
        <!-- Accordion Menu -->
        <li> <a href="#" class="nav-top-item">公司页面 </a>
          <ul>
	          <li><a href='../company/material/material_download.jsp'>资料 </a></li>
	          <li><a href='../company/notice/notice.jsp'>公告</a></li>
	          <li><a href='../company/salearea/salearea.jsp'>销售区域</a></li>
	         <!--<li><a href='../company/saleskill/saleskill.jsp'>销售技巧</a></li>-->
	          <li><a href='../company/saletarget/saletarget.jsp'>销售目标</a></li>
          </ul>
         </li>
        <li> <a href="../recepit/show_all_recepits.jsp" class="nav-top-item no-submenu">
          <!-- Add the class "current" to current menu item -->
           我的跟单</a>
        </li>
        <li> <a href="../offer/show_all_offers.jsp" class="nav-top-item no-submenu">报<span class='letter'>价</span></a>      
        </li>
        <li> <a href="../bargain/show_all_bargains.jsp" class="nav-top-item current no-submenu">合<span class='letter'>同</span></a>
        </li>
         <li> <a href="../schedule/schedule.jsp" class="nav-top-item no-submenu">日程管理</a>
        </li>
        <li> <a href="../customer/customer.jsp" class="nav-top-item no-submenu">我的客户</a>
        </li>
        <%
            if(cu.getPosition()!=1){
            	%>
            	<li> <a href="#" class="nav-top-item">统<span class='letter'>计</span></a>
		          <ul>
		            <li><a href="../../control/statistics/company_statistics.jsp">公司统计</a></li>
		            <li><a href="../../control/statistics/employees_statistics.jsp">员工统计</a></li>
		          </ul>
		        </li>
            	<li><a href="../employees/employees.jsp" class="nav-top-item no-submenu">员工管理</a></li>
            	<%
            }
        %>
      </ul>
    </div>
  </div>
  <div id="main-content">
 <form action="show_all_bargains.jsp?type=1" method="post">
	 <div class="content-box-header">
	 <h3 style="cursor: s-resize;">搜索条件</h3>
	 </div>
	 		<table border='1'>
					<tr>
						<td>是否超期</td><td><input type="radio" name="is_overdue" value="1" <%if(is_overdue!=null&&is_overdue.equals("1")) out.print("checked");%>/>是
						<input type="radio" name="is_overdue" value="0" <%if(is_overdue!=null&&is_overdue.equals("0")) out.print("checked");%>/>否
						<input type="radio" name="is_overdue" value="" <%if(is_overdue==null||is_overdue.equals("")) out.print("checked");%>/>全部</td>
						<td>
						          合同编号
						</td>
						<td>
						     <input type="text" name="bargain_id" value="<%if(bargain_id!=null && !bargain_id.equals("")) out.print(bargain_id); %>"/>
						</td>
						<td>
							当前跟单人
						</td>
						<td>
							<input type="text" name="currentPerson" value="<%if (currentPerson != null && !currentPerson.equals("")) out.print(currentPerson);%>" />
						</td>
						<td>
							合同名称
						</td>
						<td>
							<input type="text" name="title" value="<%if (title != null && !title.equals("")) out.print(title);%>" />
						</td>
						<td>
							<input type="submit" class='button' value="查询" />
						</td>
					</tr>
				</table>
		</form>
		<form>
		 <div class="content-box-header">
<h3 style="cursor: s-resize;">搜索结果</h3>
</div>
				<table>
					<thead>
						<tr>
						    <th>
						                    合同编号
						    </th>
							<th>
								合同名称
							</th>
							<th>
								成交金额
							</th>
							<th>
								回款金额
							</th>
							<th>
								最晚回款时间
							</th>
							<th>
								是否超期
							</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody>
						<%
							request.setCharacterEncoding("UTF-8");
							int pages = ParamUtil.getInt(request, "pages", 0);
							int rowsPerPage = ParamUtil.getInt(request, "pagesSize", 10);
							Collection bargain = BargainControl.searchBargain(bargain_id,title,is_overdue,
									currentPerson, rowsPerPage, pages);
							Iterator iterator = bargain.iterator();
							int i=0;
							while (iterator.hasNext()) {
								i++;
								Bargain bargain2 = (Bargain) iterator.next();
								if(bargain2.getIs_overdue().equals("0")){
									  BargainControl.updateIsOverDue(bargain2.getId());
								}
								int offer_id = bargain2.getOffer_id();
								Offer offer = new Offer();
								offer = OfferControl.getOfferById(offer_id);
								System.out.println(bargain_id);
						%>
						<tr>
						    <td align="center"><%out.print(bargain2.getBargain_id());%></td>
							<td align="center">
							
								<%
									if (bargain2.getTitle().length() > 20)
											out.print(bargain2.getTitle().substring(0, 20) + "...");
										else
											out.print(bargain2.getTitle());
								%>
							</td>
							
							<td align="center"><%=bargain2.getDeal_money()%></td>
							<td align="center"><%=bargain2.getReturned_money()%></td>
							<td align="center"><%=bargain2.getLatest_date()%></td>
							
							<%
							      if(Integer.parseInt(DateTime.Date().replace("-","").trim())>Integer.parseInt(bargain2.getLatest_date().replace("-","").trim())){
							    	  BargainControl.updateIsOverDue(bargain2.getId(),1);
							      }
							%>
							<td align="center"><%if(bargain2.getIs_overdue().equals("1")) out.print("<font color='red'>是</font>");else out.print("否");%></td>
							<td><a href="#message<%=i %>" rel='modal'>查看</a></td>
						</tr>
						 <div  class='hide' >
				        <div id='message<%=i %>'>
						<iframe id='icheck<%=i %>'style='width:368px; overflow:hidden;' scrolling='no' frameborder='0'  src='bargain_read.jsp?id=<%=bargain2.getId()%>'></iframe>
						</div>
						</div>
						<%
							}
						%>
						  <input type='hidden' id='num' value='<%=i %>'/>
					</tbody>
				</table>
				<%
					out.println(BargainControl.pageInstance.getToolsMenu(pages));
				%>
		</form>
<div class='hide' >
	<div id='information'>
		<iframe id='iinformation' style='width:368px; overflow:hidden;' scrolling='no' frameborder='0' src='../employees/employees_update.jsp'></iframe>
	</div>
</div>
		</div>
		</div>
	</body>
</html>